//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;
using System.Text;

namespace OpenLS.Chart.UI
{
    class UnitConverter
    {
        public static double Convert (double value, Unit u)
        {
            return value/GetMultiplier(u);
        }

        private static double GetMultiplier(Unit u)
        {
            if( u is BuiltInUnit)
            {
                BuiltInUnit builtInUnit = (BuiltInUnit) u;
                switch (builtInUnit.Value)
                {
                    case BuiltInUnitValue.Billions:return 1000000000;
                    case BuiltInUnitValue.HundredMillions: return 100000000;
                        case BuiltInUnitValue.Hundreds: return 100;
                        case BuiltInUnitValue.HundredThousands: return 100000;
                        case BuiltInUnitValue.Millions:return 1000000;
                        case BuiltInUnitValue.TenMillions:return 10000000;
                        case BuiltInUnitValue.TenThousands:
                        return 10000;
                        case BuiltInUnitValue.Thousands:
                        return 1000;
                        case BuiltInUnitValue.Trillions:
                        return 1e12;
                        default: throw new NotSupportedException();


                }
            }
            else if (u is CustomUnit)
            {
                return ((CustomUnit) u).Value;
            }
            throw new NotSupportedException();
        }
    }
}
